import 'package:flutter/material.dart';

///
///                    .::::.
///                  .::::::::.
///                 :::::::::::
///             ..:::::::::::'
///           '::::::::::::'
///             .::::::::::
///        '::::::::::::::..
///             ..::::::::::::.
///           ``::::::::::::::::
///            ::::``:::::::::'        .:::.
///           ::::'   ':::::'       .::::::::.
///         .::::'      ::::     .:::::::'::::.
///        .:::'       :::::  .:::::::::' ':::::.
///       .::'        :::::.:::::::::'      ':::::.
///      .::'         ::::::::::::::'         ``::::.
///  ...:::           ::::::::::::'              ``::.
/// ```` ':.          ':::::::::'                  ::::..
///                    '.:::::'                    ':'````..
///
/// Created by Wongxd on 2020/5/19.
/// https://github.com/wongxd
/// wxd1@live.com
///

///渐变效果
class CustomRoutePercent extends PageRouteBuilder {
  final Widget widget;
  final RouteSettings routeSettings;
  final Duration duration;

  CustomRoutePercent(this.widget,
      {this.duration = const Duration(milliseconds: 500), this.routeSettings})
      : super(
            settings: routeSettings,
            transitionDuration: duration,
            pageBuilder: (BuildContext context, Animation<double> animation1,
                Animation<double> animation2) {
              return widget;
            },
            transitionsBuilder: (BuildContext context,
                Animation<double> animation1,
                Animation<double> animation2,
                Widget child) {
              return FadeTransition(
                opacity: Tween(begin: 0.0, end: 2.0).animate(CurvedAnimation(
                    parent: animation1, curve: Curves.fastOutSlowIn)),
                child: child,
              );
            });
}

///缩放效果
class CustomRouteZoom extends PageRouteBuilder {
  final Widget widget;
  final RouteSettings routeSettings;
  final Duration duration;

  CustomRouteZoom(this.widget,
      {this.duration = const Duration(milliseconds: 500), this.routeSettings})
      : super(
            settings: routeSettings,
            transitionDuration: duration,
            pageBuilder: (BuildContext context, Animation<double> animation1,
                Animation<double> animation2) {
              return widget;
            },
            transitionsBuilder: (BuildContext context,
                Animation<double> animation1,
                Animation<double> animation2,
                Widget child) {
              return ScaleTransition(
                  scale: Tween(begin: 0.0, end: 1.0).animate(CurvedAnimation(
                      parent: animation1, curve: Curves.fastOutSlowIn)),
                  child: child);
            });
}

///旋转+缩放效果
class CustomRouteRotateZoom extends PageRouteBuilder {
  final Widget widget;
  final RouteSettings routeSettings;
  final Duration duration;

  CustomRouteRotateZoom(this.widget,
      {this.duration = const Duration(milliseconds: 500), this.routeSettings})
      : super(
            settings: routeSettings,
            transitionDuration: duration,
            pageBuilder: (BuildContext context, Animation<double> animation1,
                Animation<double> animation2) {
              return widget;
            },
            transitionsBuilder: (BuildContext context,
                Animation<double> animation1,
                Animation<double> animation2,
                Widget child) {
              return RotationTransition(
                  turns: Tween(begin: 0.0, end: 1.0).animate(CurvedAnimation(
                      parent: animation1, curve: Curves.fastOutSlowIn)),
                  child: ScaleTransition(
                    scale: Tween(begin: 0.0, end: 1.0).animate(CurvedAnimation(
                        parent: animation1, curve: Curves.fastOutSlowIn)),
                    child: child,
                  ));
            });
}

///滑动效果
class CustomRouteSlide extends PageRouteBuilder {
  final Widget widget;
  final RouteSettings routeSettings;
  final Duration duration;

  CustomRouteSlide(this.widget,
      {this.duration = const Duration(milliseconds: 500), this.routeSettings})
      : super(
            settings: routeSettings,
            transitionDuration: duration,
            pageBuilder: (BuildContext context, Animation<double> animation1,
                Animation<double> animation2) {
              return widget;
            },
            transitionsBuilder: (BuildContext context,
                Animation<double> animation1,
                Animation<double> animation2,
                Widget child) {
              return SlideTransition(
                position:
                    Tween<Offset>(begin: Offset(1, 0), end: Offset(0, 0))
                        .animate(CurvedAnimation(
                            parent: animation1, curve: Curves.fastOutSlowIn)),
                child: child,
              );
            });
}
